package com.householdregister.residence.controller;

import javax.servlet.http.HttpServletResponse;

import com.householdregister.common.utils.poi.ExcelUtil;
import com.householdregister.residence.domain.HouseholdResidence;
import com.householdregister.residence.service.IHouseholdResidenceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.householdregister.common.annotation.Log;
import com.householdregister.common.core.controller.BaseController;
import com.householdregister.common.core.domain.AjaxResult;
import com.householdregister.common.enums.BusinessType;
import com.householdregister.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 户口管理Controller
 * 
 * @author zyj
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/residence/residence")
public class HouseholdResidenceController extends BaseController
{
    @Autowired
    private IHouseholdResidenceService householdResidenceService;

    /**
     * 查询户口管理列表
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseholdResidence householdResidence)
    {
        startPage();
        List<HouseholdResidence> list = householdResidenceService.selectHouseholdResidenceList(householdResidence);
        return getDataTable(list);
    }

    /**
     * 查询户口管理列表
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(HouseholdResidence householdResidence)
    {
        return AjaxResult.success(householdResidenceService.selectHouseholdResidenceList(householdResidence));
    }

    /**
     * 导出户口管理列表
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:export')")
    @Log(title = "户口管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseholdResidence householdResidence)
    {
        List<HouseholdResidence> list = householdResidenceService.selectHouseholdResidenceList(householdResidence);
        ExcelUtil<HouseholdResidence> util = new ExcelUtil<HouseholdResidence>(HouseholdResidence.class);
        util.exportExcel(response, list, "户口管理数据");
    }

    /**
     * 获取户口管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(householdResidenceService.selectHouseholdResidenceById(id));
    }

    /**
     * 新增户口管理
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:add')")
    @Log(title = "户口管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseholdResidence householdResidence)
    {
        return toAjax(householdResidenceService.insertHouseholdResidence(householdResidence));
    }

    /**
     * 修改户口管理
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:edit')")
    @Log(title = "户口管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseholdResidence householdResidence)
    {
        return toAjax(householdResidenceService.updateHouseholdResidence(householdResidence));
    }

    /**
     * 删除户口管理
     */
    @PreAuthorize("@ss.hasPermi('residence:residence:remove')")
    @Log(title = "户口管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(householdResidenceService.deleteHouseholdResidenceByIds(ids));
    }

    /**
     * 查询总户籍数
     * @return
     */
    @GetMapping("/selectCountResidence")
    public AjaxResult selectCountResidence(){
        return AjaxResult.success(householdResidenceService.selectCountResidence());
    }
}
